home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Bank smakow / BankSmakow.air / BankSmakow.swf / scripts / mx / collections / ArrayList.as < prev    next >
Text File  |  2009-12-16  |  11KB  |  344 lines

  1. package mx.collections
  2. {
  3.    import flash.events.EventDispatcher;
  4.    import flash.events.IEventDispatcher;
  5.    import flash.utils.IDataInput;
  6.    import flash.utils.IDataOutput;
  7.    import flash.utils.IExternalizable;
  8.    import flash.utils.getQualifiedClassName;
  9.    import mx.core.IPropertyChangeNotifier;
  10.    import mx.core.mx_internal;
  11.    import mx.events.CollectionEvent;
  12.    import mx.events.CollectionEventKind;
  13.    import mx.events.PropertyChangeEvent;
  14.    import mx.events.PropertyChangeEventKind;
  15.    import mx.resources.IResourceManager;
  16.    import mx.resources.ResourceManager;
  17.    import mx.utils.ArrayUtil;
  18.    import mx.utils.UIDUtil;
  19.    
  20.    use namespace mx_internal;
  21.    
  22.    public class ArrayList extends EventDispatcher implements IList, IExternalizable, IPropertyChangeNotifier
  23.    {
  24.       
  25.       mx_internal static const VERSION:String = "3.5.0.12683";
  26.        
  27.       
  28.       private var _source:Array;
  29.       
  30.       private var _dispatchEvents:int = 0;
  31.       
  32.       private var _uid:String;
  33.       
  34.       private var resourceManager:IResourceManager;
  35.       
  36.       public function ArrayList(param1:Array = null)
  37.       {
  38.          resourceManager = ResourceManager.getInstance();
  39.          super();
  40.          disableEvents();
  41.          this.source = param1;
  42.          enableEvents();
  43.          _uid = UIDUtil.createUID();
  44.       }
  45.       
  46.       public function addAll(param1:IList) : void
  47.       {
  48.          addAllAt(param1,length);
  49.       }
  50.       
  51.       public function readExternal(param1:IDataInput) : void
  52.       {
  53.          source = param1.readObject();
  54.       }
  55.       
  56.       private function internalDispatchEvent(param1:String, param2:Object = null, param3:int = -1) : void
  57.       {
  58.          var _loc4_:CollectionEvent = null;
  59.          var _loc5_:PropertyChangeEvent = null;
  60.          if(_dispatchEvents == 0)
  61.          {
  62.             if(hasEventListener(CollectionEvent.COLLECTION_CHANGE))
  63.             {
  64.                (_loc4_ = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)).kind = param1;
  65.                _loc4_.items.push(param2);
  66.                _loc4_.location = param3;
  67.                dispatchEvent(_loc4_);
  68.             }
  69.             if(hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE) && (param1 == CollectionEventKind.ADD || param1 == CollectionEventKind.REMOVE))
  70.             {
  71.                (_loc5_ = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE)).property = param3;
  72.                if(param1 == CollectionEventKind.ADD)
  73.                {
  74.                   _loc5_.newValue = param2;
  75.                }
  76.                else
  77.                {
  78.                   _loc5_.oldValue = param2;
  79.                }
  80.                dispatchEvent(_loc5_);
  81.             }
  82.          }
  83.       }
  84.       
  85.       public function removeAll() : void
  86.       {
  87.          var _loc1_:int = 0;
  88.          var _loc2_:int = 0;
  89.          if(length > 0)
  90.          {
  91.             _loc1_ = length;
  92.             _loc2_ = 0;
  93.             while(_loc2_ < _loc1_)
  94.             {
  95.                stopTrackUpdates(source[_loc2_]);
  96.                _loc2_++;
  97.             }
  98.             source.splice(0,length);
  99.             internalDispatchEvent(CollectionEventKind.RESET);
  100.          }
  101.       }
  102.       
  103.       public function getItemIndex(param1:Object) : int
  104.       {
  105.          return ArrayUtil.getItemIndex(param1,source);
  106.       }
  107.       
  108.       public function removeItemAt(param1:int) : Object
  109.       {
  110.          var _loc3_:String = null;
  111.          if(param1 < 0 || param1 >= length)
  112.          {
  113.             _loc3_ = resourceManager.getString("collections","outOfBounds",[param1]);
  114.             throw new RangeError(_loc3_);
  115.          }
  116.          var _loc2_:Object = source.splice(param1,1)[0];
  117.          stopTrackUpdates(_loc2_);
  118.          internalDispatchEvent(CollectionEventKind.REMOVE,_loc2_,param1);
  119.          return _loc2_;
  120.       }
  121.       
  122.       public function addAllAt(param1:IList, param2:int) : void
  123.       {
  124.          var _loc3_:int = param1.length;
  125.          var _loc4_:int = 0;
  126.          while(_loc4_ < _loc3_)
  127.          {
  128.             this.addItemAt(param1.getItemAt(_loc4_),_loc4_ + param2);
  129.             _loc4_++;
  130.          }
  131.       }
  132.       
  133.       public function itemUpdated(param1:Object, param2:Object = null, param3:Object = null, param4:Object = null) : void
  134.       {
  135.          var _loc5_:PropertyChangeEvent;
  136.          (_loc5_ = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE)).kind = PropertyChangeEventKind.UPDATE;
  137.          _loc5_.source = param1;
  138.          _loc5_.property = param2;
  139.          _loc5_.oldValue = param3;
  140.          _loc5_.newValue = param4;
  141.          itemUpdateHandler(_loc5_);
  142.       }
  143.       
  144.       public function get uid() : String
  145.       {
  146.          return _uid;
  147.       }
  148.       
  149.       public function writeExternal(param1:IDataOutput) : void
  150.       {
  151.          param1.writeObject(_source);
  152.       }
  153.       
  154.       public function addItem(param1:Object) : void
  155.       {
  156.          addItemAt(param1,length);
  157.       }
  158.       
  159.       public function toArray() : Array
  160.       {
  161.          return source.concat();
  162.       }
  163.       
  164.       public function get source() : Array
  165.       {
  166.          return _source;
  167.       }
  168.       
  169.       public function getItemAt(param1:int, param2:int = 0) : Object
  170.       {
  171.          var _loc3_:String = null;
  172.          if(param1 < 0 || param1 >= length)
  173.          {
  174.             _loc3_ = resourceManager.getString("collections","outOfBounds",[param1]);
  175.             throw new RangeError(_loc3_);
  176.          }
  177.          return source[param1];
  178.       }
  179.       
  180.       public function set uid(param1:String) : void
  181.       {
  182.          _uid = param1;
  183.       }
  184.       
  185.       public function setItemAt(param1:Object, param2:int) : Object
  186.       {
  187.          var _loc4_:String = null;
  188.          var _loc5_:Boolean = false;
  189.          var _loc6_:Boolean = false;
  190.          var _loc7_:PropertyChangeEvent = null;
  191.          var _loc8_:CollectionEvent = null;
  192.          if(param2 < 0 || param2 >= length)
  193.          {
  194.             _loc4_ = resourceManager.getString("collections","outOfBounds",[param2]);
  195.             throw new RangeError(_loc4_);
  196.          }
  197.          var _loc3_:Object = source[param2];
  198.          source[param2] = param1;
  199.          stopTrackUpdates(_loc3_);
  200.          startTrackUpdates(param1);
  201.          if(_dispatchEvents == 0)
  202.          {
  203.             _loc5_ = hasEventListener(CollectionEvent.COLLECTION_CHANGE);
  204.             _loc6_ = hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE);
  205.             if(_loc5_ || _loc6_)
  206.             {
  207.                (_loc7_ = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE)).kind = PropertyChangeEventKind.UPDATE;
  208.                _loc7_.oldValue = _loc3_;
  209.                _loc7_.newValue = param1;
  210.                _loc7_.property = param2;
  211.             }
  212.             if(_loc5_)
  213.             {
  214.                (_loc8_ = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)).kind = CollectionEventKind.REPLACE;
  215.                _loc8_.location = param2;
  216.                _loc8_.items.push(_loc7_);
  217.                dispatchEvent(_loc8_);
  218.             }
  219.             if(_loc6_)
  220.             {
  221.                dispatchEvent(_loc7_);
  222.             }
  223.          }
  224.          return _loc3_;
  225.       }
  226.       
  227.       public function get length() : int
  228.       {
  229.          if(source)
  230.          {
  231.             return source.length;
  232.          }
  233.          return 0;
  234.       }
  235.       
  236.       private function disableEvents() : void
  237.       {
  238.          --_dispatchEvents;
  239.       }
  240.       
  241.       protected function itemUpdateHandler(param1:PropertyChangeEvent) : void
  242.       {
  243.          var _loc2_:PropertyChangeEvent = null;
  244.          var _loc3_:uint = 0;
  245.          internalDispatchEvent(CollectionEventKind.UPDATE,param1);
  246.          if(_dispatchEvents == 0 && hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
  247.          {
  248.             _loc2_ = PropertyChangeEvent(param1.clone());
  249.             _loc3_ = getItemIndex(param1.target);
  250.             _loc2_.property = _loc3_.toString() + "." + param1.property;
  251.             dispatchEvent(_loc2_);
  252.          }
  253.       }
  254.       
  255.       public function addItemAt(param1:Object, param2:int) : void
  256.       {
  257.          var _loc3_:String = null;
  258.          if(param2 < 0 || param2 > length)
  259.          {
  260.             _loc3_ = resourceManager.getString("collections","outOfBounds",[param2]);
  261.             throw new RangeError(_loc3_);
  262.          }
  263.          source.splice(param2,0,param1);
  264.          startTrackUpdates(param1);
  265.          internalDispatchEvent(CollectionEventKind.ADD,param1,param2);
  266.       }
  267.       
  268.       public function removeItem(param1:Object) : Boolean
  269.       {
  270.          var _loc2_:int = getItemIndex(param1);
  271.          var _loc3_:* = _loc2_ >= 0;
  272.          if(_loc3_)
  273.          {
  274.             removeItemAt(_loc2_);
  275.          }
  276.          return _loc3_;
  277.       }
  278.       
  279.       protected function stopTrackUpdates(param1:Object) : void
  280.       {
  281.          if(param1 && param1 is IEventDispatcher)
  282.          {
  283.             IEventDispatcher(param1).removeEventListener(PropertyChangeEvent.PROPERTY_CHANGE,itemUpdateHandler);
  284.          }
  285.       }
  286.       
  287.       protected function startTrackUpdates(param1:Object) : void
  288.       {
  289.          if(param1 && param1 is IEventDispatcher)
  290.          {
  291.             IEventDispatcher(param1).addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,itemUpdateHandler,false,0,true);
  292.          }
  293.       }
  294.       
  295.       override public function toString() : String
  296.       {
  297.          if(source)
  298.          {
  299.             return source.toString();
  300.          }
  301.          return getQualifiedClassName(this);
  302.       }
  303.       
  304.       private function enableEvents() : void
  305.       {
  306.          ++_dispatchEvents;
  307.          if(_dispatchEvents > 0)
  308.          {
  309.             _dispatchEvents = 0;
  310.          }
  311.       }
  312.       
  313.       public function set source(param1:Array) : void
  314.       {
  315.          var _loc2_:int = 0;
  316.          var _loc3_:int = 0;
  317.          var _loc4_:CollectionEvent = null;
  318.          if(_source && _source.length)
  319.          {
  320.             _loc3_ = _source.length;
  321.             _loc2_ = 0;
  322.             while(_loc2_ < _loc3_)
  323.             {
  324.                stopTrackUpdates(_source[_loc2_]);
  325.                _loc2_++;
  326.             }
  327.          }
  328.          _source = !!param1 ? param1 : [];
  329.          _loc3_ = _source.length;
  330.          _loc2_ = 0;
  331.          while(_loc2_ < _loc3_)
  332.          {
  333.             startTrackUpdates(_source[_loc2_]);
  334.             _loc2_++;
  335.          }
  336.          if(_dispatchEvents == 0)
  337.          {
  338.             (_loc4_ = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)).kind = CollectionEventKind.RESET;
  339.             dispatchEvent(_loc4_);
  340.          }
  341.       }
  342.    }
  343. }
  344.